 // Yes, this is practically all Garry's code. With some simplifications and modifications
 
TOOL.Tab 			= "Fallen Menu"
TOOL.Category		= "Shuttle"
 TOOL.Name			= "#Shuttle Tool" 
 TOOL.Command		= nil 
 TOOL.ConfigName		= "" 

TOOL.ClientConVar["life"] = "500"
TOOL.ClientConVar["speed"] = "100"
TOOL.ClientConVar["power"] = "10000"
TOOL.ClientConVar["turn"] = "0"
TOOL.ClientConVar["roll"] = "1"
TOOL.ClientConVar["ahover"] = "0"
TOOL.ClientConVar["aactive"] = "0"

 // Add Default Language translation (saves adding it to the txt files) 
 if ( CLIENT ) then 
 	language.Add( "Tool_shuttle_name", "Shuttle Tool" ) 
 	language.Add( "Tool_shuttle_desc", "Make any non-constrained prop into a shuttle" ) 
 	language.Add( "Tool_shuttle_0", "Click a prop to turn it into a shuttle." ) 
   
 	language.Add( "Undone_shuttle", "Undone Shuttle" ) 
 	language.Add( "Cleanup_shuttle", "Shuttles" ) 
 	language.Add( "Cleaned_shuttle", "Cleaned up all Shuttles" ) 
   
 end
 
if (SERVER) then
	CreateConVar("sbox_maxshuttles", 5)
	CreateConVar("shuttle_sv_rd_use", 1)
	CreateConVar("shuttle_sv_rd_force_disable", 0)
	CreateConVar("shuttle_sv_rd_consumerate", 1)
end
 
cleanup.Register( "shuttle" ) 

function TOOL:LeftClick( trace, attach ) 
 	local ent = trace.Entity 

 	// Has to be an entity 
 	if ( not ent or not ent:IsValid() ) then return false end 
 	 
 	// Has to be a prop - or a shuttle
 	if ( ent:GetClass() != "prop_physics" and ent:GetClass() != "shuttle") then return false end 
   
 	if (CLIENT) then return true end 
   
 	// If there's no physics object then we can't constraint it! 
 	if SERVER and !util.IsValidPhysicsObject( ent, trace.PhysicsBone ) then return false end 
   
 	local pl = self:GetOwner() 
   
 	if ( not self:GetSWEP():CheckLimit( "shuttles" ) ) then return false end 
   
 	local EntTable = duplicator.CopyEntTable( trace.Entity ) 
 	 
 	local shuttle = MakeShuttle( pl, EntTable ) 
 	 if (!shuttle:IsValid()) then 
		pl:PrintMessage(2, "Shuttle spawning failed")
		pl:PrintMessage(HUD_PRINTCENTER, "Shuttle spawning failed!")
		return
	end
   
 	ent:Remove() 
   
 	undo.Create("Shuttle") 
 	undo.AddEntity( shuttle ) 
 	undo.SetPlayer( pl ) 
 	undo.Finish() 
   
 	pl:AddCleanup( "shuttle", shuttle ) 
   
 	return true 
 end 
   
 function MakeShuttle( pl, Data ) 
 	if ( not pl:CheckLimit( "shuttles" ) ) then return nil end 

	local shuttle = ents.Create( "spawnable_shuttle" ) 
 	if (!shuttle:IsValid()) then 
		pl:PrintMessage(2, "Shuttle spawning failed")
		pl:PrintMessage(HUD_PRINTCENTER, "Shuttle spawning failed!")
		return
	end

 	duplicator.DoGeneric( shuttle, Data ) 

 	shuttle:Spawn() 

 	duplicator.DoGenericPhysics( shuttle, pl, Data ) 

	shuttle.Player 	= pl 

 	pl:AddCount( "shuttles", shuttle ) 
   
 	return shuttle 
 end 
   
 duplicator.RegisterEntityClass( "shuttle", MakeShuttle, "Data" ) 
   
   
function TOOL.BuildCPanel( CPanel )
	// HEADER
	CPanel:AddControl( "Header", { Text = "#Tool_shuttle_name", Description	= "#Tool_shuttle_desc" }  ) 
	CPanel:Help("Original Shuttle SENT by Catdaemon. \n .\nSTool and future modifications by Big Bang & WolfFallen & creec. Catdaemon is the one who deserves most credit though.\n .\nINSTRUCTIONS.\n .\nSelect the STool from the Shuttle menu, in the list of contraptions..\nClick on any prop you want to transform it into a shuttle (Note:The prop cannot have any constraints already attached to it. You can weld anything you want to a shuttle though).\nPress your Use key (Default E) on the prop you transformed into a shuttle, and you're all set to fly around now! Read the on screen instructions to see how to make it fly.");
	
	CPanel:Help("\n ---------- \n")
 	CPanel:Help( "Every setting has effect on energy usage, unless RD usage is disabled." )
	CPanel:Help("\n ---------- \n")

	CPanel:Help("\nThis is the power of shuttle, affects resources capacity and force of shuttle.")
	CPanel:AddControl("Slider",{Label = "#Shuttle power",
					Type = "Integer", 
					Min = 1000, 
					Max = 100000, 
					Command = "shuttle_power"}
					)

	CPanel:Help("\n\nThis is the speed of shuttle.")
	CPanel:AddControl("Slider",{Label = "#Shuttle speed %",
					Type = "Integer", 
					Min =  10, 
					Max =  1000, 
					Command = "shuttle_speed"}
					)

	CPanel:Help("\n\nThis is the health of shuttle.")
	CPanel:AddControl("Slider",{Label = "#Shuttle life",
					Type = "Integer", 
					Min = 100, 
					Max = 10000, 
					Command = "shuttle_life"}
					)
	
	CPanel:Help("\nThis doesn't have effect on energy usage. Turns model 180* degrees.")
	CPanel:AddControl("Checkbox", {Label = "#Turn shuttle 180*", 
					Command = "shuttle_turn"}
					)
	
	CPanel:Help("\nThis doesn't have effect on energy usage. Enables rotating of shuttle by pressing (A,D)")
	CPanel:AddControl("Checkbox", {Label = "#Shuttle rotate", 
					Command = "shuttle_roll"}
					)
	
	CPanel:Help("\nThis has slight effect on energy usage. Makes shuttle always hover, even when not moving")
	CPanel:AddControl("Checkbox", {Label = "#Shuttle hover always", 
					Command = "shuttle_ahover"}
					)
	
	CPanel:Help("\nMake shuttle be always active.")
	CPanel:AddControl("Checkbox", {Label = "#Shuttle always active", 
					Command = "shuttle_aactive"}
					)
end